/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SideTrolleyView.java
 *
 * Created on 2011-feb-18, 23:28:52
 */

package imat;

import javax.swing.JLabel;
import javax.swing.JPanel;


/**
 *
 * @author Andreas
 */
public class SideTrolleyView extends ImagePanel{
    private SideTrolleyPresenter sideTrolleyPresenter;
    private boolean visible = true;


    /** Creates new form SideTrolleyView */
    public SideTrolleyView() {
        initComponents();

        sideTrolleyPresenter = new SideTrolleyPresenter(this);
    }

    public JPanel getShoppingItemsPanel() {
        return shoppingItemsPanel;
    }

    public JLabel getTotalPriceLabel() {
        return totalPriceLabel;
    }

    public void showSideTrolley() {
        if (!visible) {
            initComponents();
            DataHandler.getInstance().getShoppingCart().fireShoppingCartChanged();
            visible = true;
        }
    }

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        shoppingItemsPanel = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        totalPriceLabel = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(imat.IMatApp.class).getContext().getResourceMap(SideTrolleyView.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setImage(resourceMap.getString("Form.image")); // NOI18N
        setPreferredSize(new java.awt.Dimension(200, 431));

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setToolTipText(resourceMap.getString("jButton1.toolTipText")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkoutButtonPressed(evt);
            }
        });

        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setToolTipText(resourceMap.getString("jButton2.toolTipText")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonPressed(evt);
            }
        });

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setPreferredSize(new java.awt.Dimension(180, 342));
        jPanel1.setLayout(new java.awt.BorderLayout());

        jScrollPane1.setName("jScrollPane1"); // NOI18N
        jScrollPane1.setPreferredSize(new java.awt.Dimension(180, 0));
        jScrollPane1.getVerticalScrollBar().setUnitIncrement(100);

        shoppingItemsPanel.setBackground(resourceMap.getColor("shoppingItemsPanel.background")); // NOI18N
        shoppingItemsPanel.setName("shoppingItemsPanel"); // NOI18N
        shoppingItemsPanel.setPreferredSize(new java.awt.Dimension(150, 0));
        shoppingItemsPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 2));
        jScrollPane1.setViewportView(shoppingItemsPanel);

        jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        totalPriceLabel.setFont(resourceMap.getFont("totalPriceLabel.font")); // NOI18N
        totalPriceLabel.setText(resourceMap.getString("totalPriceLabel.text")); // NOI18N
        totalPriceLabel.setName("totalPriceLabel"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(totalPriceLabel))
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jLabel1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(totalPriceLabel)
                    .addComponent(jLabel2))
                .addGap(8, 8, 8)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void checkoutButtonPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkoutButtonPressed
        sideTrolleyPresenter.checkout();
    }//GEN-LAST:event_checkoutButtonPressed

    private void saveButtonPressed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonPressed
        sideTrolleyPresenter.save();
    }//GEN-LAST:event_saveButtonPressed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel shoppingItemsPanel;
    private javax.swing.JLabel totalPriceLabel;
    // End of variables declaration//GEN-END:variables

    public void hideSideTrolley() {
        DataHandler.getInstance().getMainWindow().payView.updateInfo();
        removeAll();
        repaint();
        visible = false;
    }

}
